package cn.cvs.servlet;

import cn.cvs.dao.PowerBatteryMapper;
import cn.cvs.pojo.PowerBattery;
import cn.cvs.service.PowerBatteryService;
import cn.cvs.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/insert")
public class InsertServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        PowerBatteryService service = new PowerBatteryService();
        PowerBattery powerBattery = new PowerBattery();
        powerBattery.setId(id);
        powerBattery.setCarName(req.getParameter("name"));
        powerBattery.setCityName(req.getParameter("city"));
        powerBattery.setUserName(req.getParameter("user"));
        powerBattery.setTime(req.getParameter("time"));
        powerBattery.setPressureValue(Integer.parseInt(req.getParameter("values")));
        int count = service.insert(powerBattery);
        PrintWriter out = resp.getWriter();
        if (count>0){
            out.print("<script>\n" +
                    "  alert(\"修改成功!!\")\n" +
                    "  location.href=\"list\"\n" +
                    "</script>");
        }else{
            out.print("<script>\n" +
                    "  alert(\"修改失败!!\")\n" +
                    "  history.back();\n" +
                    "</script>");
        }
    }
}
